package com.hbnu.collection;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author kittychen
 * @since 2025-10-17 8:20
 */
public class HashSetDemo {
    public static void main(String[] args) {
        Set<String> hashSet = new HashSet<>();

        hashSet.add("element4");
        hashSet.add("element1");
        hashSet.add("element6");
        hashSet.add("element3");
        hashSet.add("element4");
        System.out.println(hashSet);

        System.out.println(hashSet.contains("element1"));
        System.out.println(hashSet.isEmpty());
        hashSet.remove("element1");
        System.out.println(hashSet);
        System.out.println(hashSet.size());

        System.out.println("======================");
        for (String s : hashSet) {
            System.out.println(s);
        }

        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        hashSet.stream().iterator().forEachRemaining(System.out::println);

        hashSet.stream().forEach(System.out::println);
    }
}
